ActiveReports 8 > ActiveReports User Guide > How To > Section Report How To > Work with Report Controls > Add Field Expressions |
In a section report, expressions can be used in the DataField property to specify textbox output in a report, such as date/time, mathematical calculations or conditional values. All field expressions used in the DataField property begin with the equals sign (=).
To use a mathematical expression
Set the DataField property of a textbox control to a mathematical calculation.
Example:
=UnitPrice+5
=Quantity-5
=Quantity*UnitPrice
=UnitPrice/QuantityPerUnit
To use a substring
Set the DataField property of a textbox control to the required substring. While setting up grouping, change the GroupHeader's DataField property to the same substring.
Example:
=ProductName.Substring(0, 1)
To use date/time
Set the DataField property of a textbox control similar to the following expression to display date/time values.
Example:
=System.DateTime.Now.ToString()
To create a conditional value
Set the DataField property of a textbox control to the conditional statement as desired.
Example:
=(UnitsInStock > 0)?"In Stock":"Backorder"
To concatenate fields
Set the DataField property of a textbox control similar to the following expression to display concatenated fields.
Example:
="There are " + UnitsInStock + " units of " + ProductName + " in stock."
=TitleOfCourtesy + " " + FirstName + " " + LastName
Note: ActiveReports automatically handles null values, replacing them with an empty string. |
To round a calculation
Set the DataField Property of a textbox control like the following example.
Example:
=(double)System.Math.Round(UnitsInStock/10)
To use modular division
Set the DataField property of a textbox control like the following example to get the remainder (2 in this case).
Example: =22%(5)
To replace a null value
Set the DataField property of a textbox control like the following example to replace null with your own value.
Example:
=(UnitsInStock == System.DBNull.Value) ? "No Units In Stock" : UnitsInStock